package cn.kgc.vueebook3.service.impl;

import cn.kgc.vueebook3.mapper.EntryMapper;
import cn.kgc.vueebook3.pojo.Entry;
import cn.kgc.vueebook3.pojo.EntryExample;
import cn.kgc.vueebook3.service.EntryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class EntryServiceImpl implements EntryService{
    @Resource
    EntryMapper entryMapper;
    @Override
    public PageInfo<Entry> select(Integer pageNum, Integer pageSize, Integer categoryId) {
        PageHelper.startPage(pageNum,pageSize);
        List<Entry> entryList;
        if (categoryId!=0){
            EntryExample example=new EntryExample();
            EntryExample.Criteria criteria=example.createCriteria();
            criteria.andCategoryidEqualTo(categoryId);
             entryList=entryMapper.selectByExample(example);
        }else {
            entryList = entryMapper.selectByExample(null);
        }
        PageInfo<Entry> pageInfo=new PageInfo<>(entryList);
        return pageInfo;
    }

    @Override
    public Integer add(Entry entry) {
        int i=entryMapper.insert(entry);
        return i;
    }

    @Override
    public Entry selectById(Integer id) {
        Entry entry=entryMapper.selectByPrimaryKey(id);
        return entry;
    }

    @Override
    public Integer update(Entry entry) {
        int i=entryMapper.updateByPrimaryKeySelective(entry);
        return i;
    }

    @Override
    public Integer delete(Integer id) {
        int i=entryMapper.deleteByPrimaryKey(id);
        return i;
    }


}
